/**
 * Created by hanj on 2022/6/14 10:13
 */
package com.example.miniotest;

import io.minio.MinioClient;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Setter
@Getter
@Component
@ConfigurationProperties(prefix = "minio")
public class MinIOConfig {

    /**
     * 服务端口
     */
    private String endpoint;

    /**
     * access秘钥
     */
    private String accessKey;

    /**
     * secret秘钥
     */
    private String secretKey;

    /**
     * 获取断点上传实体
     *
     * @return
     */
    @Bean
    @SneakyThrows
    @ConditionalOnMissingBean(PearlMinIOClient.class)
    public PearlMinIOClient getPearMinIOClient() {
        MinioClient minioClient = getMinIOClient();
        return new PearlMinIOClient(minioClient);
    }

    /**
     * 获取minio实体
     *
     * @return
     */
    public MinioClient getMinIOClient() {
        return MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
    }


}
